//
//  ViewController.m
//  HttpRequestDemo
//
//  Created by joker on 15/6/19.
//  Copyright (c) 2015年 joker. All rights reserved.
//

#import "loginViewController.h"

#import "ASIFormDataRequest.h"
#import "ASIHTTPRequest.h"
#import "ASIHTTPRequestConfig.h"

#import "UtilitiesFunctions.h"
#import "bulltinBoardListTableViewController.h"
#import "AppDelegate.h"


@interface loginViewController ()

@end

@implementation loginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)logIn:(UIButton *)sender {
    //获取控件中的用户名和密码信息
    NSString *userName;
    NSString *userPassword;
    
#ifdef _FOR_TEST
    userName=@"02244";
    userPassword=@"1";
#else
    userName=self.userName.text;
    userPassword=self.userPassword.text;
#endif

    
    NSString *returnValueJSONString=[UtilitiesFunctions logInOAWithUserName: userName AndUserPasswords:userPassword];
    
    if(returnValueJSONString!=nil){
        NSData *returnValueDataFromJSONString=[returnValueJSONString dataUsingEncoding:NSUTF8StringEncoding];
        NSError *error;
        NSDictionary *returnValueDictionaryFromData=[NSJSONSerialization JSONObjectWithData:returnValueDataFromJSONString options:NSJSONReadingMutableLeaves error:&error];
        if(!error)
        {
            self.userInformation=returnValueDictionaryFromData;
            [self performSegueWithIdentifier:@"showTableViewList" sender:self];
        }
    }
    else
    {
        self.userName.text=@"";
        self.userPassword.text=@"";
    }
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    UINavigationController *navigationController=segue.destinationViewController;
    
    bulltinBoardListTableViewController *tableListViewController=navigationController.viewControllers.firstObject;
    
    tableListViewController.UserInformationDictionary=self.userInformation;
    
    AppDelegate *appDelegate=[[UIApplication sharedApplication] delegate] ;
    appDelegate.isLoginSuccessfully=YES;
    appDelegate.tableListViewController=tableListViewController;

    if(self.tempItem){
        [tableListViewController.bulltinItemsArray addObject:self.tempItem];
    }
}
@end
